﻿using System;
using System.Net;
using System.Net.Sockets;
using System.IO;

namespace ChatClientApp.Classes
{
    class ServerConnection
    {
        TcpClient tcp;
        StreamReader sr;
        StreamWriter wr;

        public ServerConnection(IPEndPoint ipe)
        {
            tcp = new TcpClient();
            tcp.Connect(ipe);
            sr = new StreamReader(tcp.GetStream());
            wr = new StreamWriter(tcp.GetStream());
        }

        public void write(string message)
        {
            wr.WriteLine(message);
            wr.Flush();
        }

        public string read()
        {
            return sr.ReadLine();
        }

        public string readToEnd()
        {
            string ret = String.Empty;
            while (!sr.EndOfStream)
            {
                ret += sr.ReadLine();
                if (!sr.EndOfStream)
                    ret += "\r\n";
            }
            return ret;
        }
    }
}
